<template>
  <div class="app-container">
    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="名称" width="180" />

      <el-table-column label="头衔" width="80">
        <template slot-scope="scope">
          {{ scope.row.level===1?'大佬':'究极大佬' }}
        </template>
      </el-table-column>

      <el-table-column prop="intro" label="资历" />

      <el-table-column prop="gmtCreate" label="添加时间" width="160"/>

      <el-table-column prop="sort" label="排序" width="60" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/edu/teacher/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
       <!-- 分页 -->
        <el-pagination
          :current-page="page"
          :page-size="limit"
          :total="total"
          style="padding: 30px 0; text-align: center;"
          layout="total, prev, pager, next, jumper"
          @current-change="getTeacherListPage"
        />
  </div>
</template>


<script>
  // 引入 js 文件，后编写核心代码
  import teacher from '@/api/edu/teacher'

  export default {
    // data: {
    // },

    data() {
      return {
        list: null, //查询之后返回接口集合
        page: 1, //当前页数
        limit: 10, //每页记录数
        total: 0, //总记录数
        teacherQuery: {} //条件封装对象
      }
    },
    created() {
      this.getTeacherListPage()
    },
    methods: {
      getTeacherListPage(page = 1) {
        this.page = page
        teacher.getTeacherListPage(this.page, this.limit, this.teacherQuery)
          .then(response => { //请求成功
            // response 接口返回的数据
            console.log(response.data.rows)
            this.list = response.data.rows
            this.total = response.data.total
          })
          .catch() //请求失败
      }
    }

  }
</script>
